package com.wake.mycomposebook.ui.home.layouts

import android.content.Context
import android.view.Gravity
import android.widget.Button
import android.widget.TextView
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.LocalContentColor
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.wake.lottie.MyLottieFood
import com.wake.mycomposebook.utils.showLog

/**
 *@author created by WA03675
 *@date  2022-04-20 15:31
 *@des
 */

/**
 * Android视图转Compose
 *
 */
@Composable
fun MyAndroidView() {
    val context = LocalContext.current
    Column(Modifier.verticalScroll(rememberScrollState())) {

        MyTextView(context)
        MyButton(context)
        MyLottieView(context)

    }
}


@Composable
fun MyTextView(context: Context) {
    val color = LocalContentColor.current.toArgb()
    val tv = remember {
        TextView(context).apply {
            text = "我列阵在南"
            setTextColor(color)
            gravity = Gravity.CENTER
        }
    }

    AndroidView(
        { tv },
        Modifier
            .fillMaxWidth()
            .height(40.dp)
            .border(1.dp, Color.Red)
    )

}

@Composable
fun MyButton(context: Context) {

    var count by remember {
        mutableStateOf(0)
    }

    val bt = remember {
        Button(context).apply {
            setOnClickListener {
                count++
            }
            text = "点击了 $count 次"
        }
    }

    AndroidView({ bt },
        Modifier
            .width(100.dp)
            .height(60.dp)
            .border(1.dp, Color.Red)
    ){
        it.text = "点了$count 次"
    }
}

@Composable
fun MyLottieView(context: Context) {
    MyLottieFood(context = context)
}

